aboutsummaryrefslogtreecommitdiffstats
path: root/src/pages/article/[slug].tsx
diff options
context:
space:
mode:
authorArmand Philippot <git@armandphilippot.com>2023-12-12 18:50:03 +0100
committerArmand Philippot <git@armandphilippot.com>2023-12-12 18:50:03 +0100
commit85c4c42bd601270d7be0f34a0767a34bb85e29bb (patch)
tree16a07a89cf209139672592fd6988f0c028acb7e9 /src/pages/article/[slug].tsx
parent93f87c10783e3d76f1dec667779aedffcae33a39 (diff)
refactor(hooks): rewrite useBreadcrumbs hook
* use next/router to get the slug instead of using props * handle cases where the current page title is not provided * update JSON-LD schema to match the example in documentation * add tests
Diffstat (limited to 'src/pages/article/[slug].tsx')
-rw-r--r--src/pages/article/[slug].tsx16
1 files changed, 5 insertions, 11 deletions
diff --git a/src/pages/article/[slug].tsx b/src/pages/article/[slug].tsx
index bd102a9..6333056 100644
--- a/src/pages/article/[slug].tsx
+++ b/src/pages/article/[slug].tsx
@@ -46,7 +46,7 @@ import {
import { loadTranslation, type Messages } from '../../utils/helpers/server';
import {
useArticle,
- useBreadcrumb,
+ useBreadcrumbs,
useComments,
useHeadingsTree,
usePrism,
@@ -74,10 +74,9 @@ const ArticlePage: NextPageWithLayout<ArticlePageProps> = ({ data }) => {
contentId: article.id,
},
});
- const { items: breadcrumbItems, schema: breadcrumbSchema } = useBreadcrumb({
- title: data.post.title,
- url: data.post.slug,
- });
+ const { items: breadcrumbItems, schema: breadcrumbSchema } = useBreadcrumbs(
+ article.title
+ );
const { ref, tree } = useHeadingsTree<HTMLDivElement>({ fromLevel: 2 });
const { attributes, className: prismClassName } = usePrism({
attributes: {
@@ -172,6 +171,7 @@ const ArticlePage: NextPageWithLayout<ArticlePageProps> = ({ data }) => {
webpageSchema,
blogSchema,
blogPostSchema,
+ breadcrumbSchema,
...getCommentsSchema(comments),
]);
@@ -208,12 +208,6 @@ const ArticlePage: NextPageWithLayout<ArticlePageProps> = ({ data }) => {
// eslint-disable-next-line react/no-danger -- Necessary for schema
dangerouslySetInnerHTML={{ __html: JSON.stringify(schemaJsonLd) }}
/>
- <Script
- dangerouslySetInnerHTML={{ __html: JSON.stringify(breadcrumbSchema) }}
- // eslint-disable-next-line react/jsx-no-literals -- Id allowed
- id="schema-breadcrumb"
- type="application/ld+json"
- />
<PageHeader
heading={title}
intro={intro}